package exportador;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class ExportadorImagen {
	
	private JPanel panelExp;
	
	public ExportadorImagen(JPanel panelExp)
	{
		this.panelExp = panelExp;
	}
	
	public void guardar(String nombre, String tipo) throws IOException
	{
	  	BufferedImage image = getImagen();
  		ImageIO.write(image, tipo, new File( nombre + "." + tipo));
	}
	
	private BufferedImage getImagen() 
	{
		BufferedImage image = (BufferedImage)panelExp.createImage(panelExp.getWidth(), panelExp.getHeight());
	  	Graphics g = image.getGraphics();
	  	
	  	panelExp.paint(g);
	  	g.dispose();
	  	
		return image;
	}

}
